﻿using System;
using System.Linq;

using Buddy.BehaviorTree;
using Buddy.CommonBot;
using Buddy.Swtor;
using Buddy.Swtor.Objects;

using WingIt;
using WingIt.Dynamics;
using WingIt.Routines.Mirrors;

namespace WingIt.Routines
{
    /* We use Resource Percent so we don't need 2 different classes
     * 100 is the Resource max and 0 the Resource min.
     * 
     * Trooper = 12 Cells = 100 Resource
     *           1 Cell = 8,4 Resource
     */
    [RevisionControlId("$Id: BountyHunterTrooperBasic.cs 686 2012-08-12 16:12:20Z Chinajade $")]
    public class BountyHunterTrooper : MirrorRoutine
    {
        // MAINTAINERS NOTES:
        // * You will notice that lambda expression argument names are unique (e.g., "darkWardOn", "darkWardWhen", "joltWhen"),
        //   instead of generic (e.g., "ctx", "ret", "on", "doWhen", "castWhen").  PLEASE honor this convention!
        //   This allows us to quickly localize problems when looking at user's logs.  When the BehaviorTree encounters an exception
        //   (e.g., "object not found"), the location where an exception is thrown is identifiable only through the name
        //   of the lambda expression argument.  Such is the nature of BehaviorTrees.

        [Behavior(BehaviorType.Pull)]
        [Class(CharacterClass.BountyHunter)]
        [Class(CharacterClass.BountyHunter, AdvancedClass.Mercenary, SkillTreeId.None)]
        [Class(CharacterClass.BountyHunter, AdvancedClass.Powertech, SkillTreeId.None)]
        [Class(CharacterClass.Trooper)]
        [Class(CharacterClass.Trooper, AdvancedClass.Commando, SkillTreeId.None)]
        [Class(CharacterClass.Trooper, AdvancedClass.Vanguard, SkillTreeId.None)]
        public static Composite BountyHunterTrooper_Pull()
        {
            return new PrioritySelector(
                LazyRaider.CreateBTPS_NotifyAndShortCircuitWhenCombatDisabled(),
                CreateBTPS.BWcoreFixup_WaitForHarvestComplete(),
                TargetSelect.CreateBTPS_UpdateForBattlefieldConditions(),

                BountyHunterTrooper_Combat()
                );
        }
        
        [Behavior(BehaviorType.Combat)]
        [Class(CharacterClass.BountyHunter)]
        [Class(CharacterClass.BountyHunter, AdvancedClass.Mercenary, SkillTreeId.None)]
        [Class(CharacterClass.BountyHunter, AdvancedClass.Powertech, SkillTreeId.None)]
        [Class(CharacterClass.Trooper)]
        [Class(CharacterClass.Trooper, AdvancedClass.Commando, SkillTreeId.None)]
        [Class(CharacterClass.Trooper, AdvancedClass.Vanguard, SkillTreeId.None)]
        public static Composite BountyHunterTrooper_Combat()
        {
            return new PrioritySelector(
                LazyRaider.CreateBTPS_NotifyAndShortCircuitWhenCombatDisabled(),
                TargetSelect.CreateBTPS_UpdateForBattlefieldConditions(),

                CreateBTPS.MoveWithinRangeAndLoS(target => MyTarget, Global.Distance.Ranged),
                CreateBTPS.StopWithinRangeAndLoS(target => MyTarget, Global.Distance.Ranged),

                //***General***
                Cast("Determination", determinationWhen => Me.IsStunned),//Insignia
                Cast("Vent Heat", ventHeatOn => Me, ventHeatWhen => Me.ResourcePercent() < 60),//-50 Heat

                //**Offensive**
                //CastOnGround("Death from Above", deathFromAboveWhen => Me.ResourceStat <= 67, MyTarget.Position),
                Cast("Rail Shot"),
                Cast("Explosive Dart", explosiveDartWhen => Me.MobCountAttacking() >= 2 && Me.ResourcePercent() >= 67),
                Cast("Unload", unloadWhen => Me.ResourcePercent() >= 67),//+16 Heat/15s CD
                Cast("Rocket Punch", rocketPunchWhen => Me.ResourcePercent() >= 67),//Melee
                Cast("Missile Blast", missleBlastWhen => Me.ResourcePercent() >= 67),//+25 Heat
                Cast("Flame Thrower", flameThrowerWhen => Me.ResourcePercent() >= 67 && Me.MobCountAround(1f) >= 3),
                Cast("Rapid Shots")
                );
        }

        [Behavior(BehaviorType.OutOfCombat)]
        [Class(CharacterClass.BountyHunter)]
        [Class(CharacterClass.BountyHunter, AdvancedClass.Mercenary, SkillTreeId.None)]
        [Class(CharacterClass.BountyHunter, AdvancedClass.Powertech, SkillTreeId.None)]
        [Class(CharacterClass.Trooper)]
        [Class(CharacterClass.Trooper, AdvancedClass.Commando, SkillTreeId.None)]
        [Class(CharacterClass.Trooper, AdvancedClass.Vanguard, SkillTreeId.None)]
        public static Composite BountyHunterTrooper_OutOfCombat()
        {
            // NB: Apparently, BWcore will call this routine when in combat on occasion.  It is also called while we're pulling.
            return (new PrioritySelector(
                TargetSelect.CreateBTPS_UpdateForBattlefieldConditions(),
                new Decorator(oocBuffWhen => !Me.IsMounted,
                    new PrioritySelector(
                        BuffSelf("Combustible Gas Cylinder")
                        ))
                ));
        }
    }
}


